<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<title>用户编辑</title>
<block th:replace="commonBase"></block>   
</head>
<body>
<div class="mini-fit">
	<form id="form1" method="post">
	    <input id="id" name="id" class="mini-hidden" />
			<div style="padding-left:25px;padding-bottom:5px;">
			<table style="margin-top: 8px;border-collapse:separate; border-spacing:0px 5px;">
				<tr>
					<td align="right">名称：</td>
					<td><input name="name" class="mini-textbox" style="width:355px;"
						required="true" requiredErrorText="不可为空" emptyText="名称" /><span><font color="red">*</font></span>
					</td>
				</tr>
				<tr>
					<td align="right">年龄：</td>
					<td><input name="age" class="mini-textbox" style="width:355px;" 
					required="true" vtype="int" requiredErrorText="不可为空" emptyText="年龄" /><span><font color="red">*</font></span>
					</td>
				</tr>
				<tr>
					<td align="right">备注：</td>
					<td ><input name="remark" class="mini-textarea"
						style="width:355px;" />
					</td>
				</tr>

			</table>
		</div>
	</form>
	</div>
	<div class="mini-toolbar" style="text-align:center;height:40px;padding-top:10px;padding-bottom:8px;" 
        borderStyle="border-left:0;border-bottom:0;border-right:0;">
        <a class="mini-button" onclick="onOk" plain="true" iconCls="fa fa-save" style="width:85px;margin-right:20px;">保存</a>
        <span style="display:inline-block;width:25px;"></span>
        <a class="mini-button" onclick="onCancel" plain="true" iconCls="fa fa-close" style="width:85px;">关闭</a>
    </div>
</body>
<script type="text/javascript">
 /*<![CDATA[*/
	mini.parse();
	var action = "new";
	var form = null;
	function setData(data) {
		
		action = data.action;//获取指令，是新增 还是修改
		form = new mini.Form("#form1");//获取表单对象
		data = mini.clone(data);//获取克隆数据
	    if (action == "edit") {
	        //跨页面传递的数据对象，克隆后才可以安全使用
	        data = mini.clone(data);
	        form.setData(data.person);
		 	form.setChanged(false);
	    }else{
	    	data = mini.clone(data);
	    }
	}
	
	//新增xx
	function personAdd(json){
		$.ajax({
	        url: basePath+"example/person/add",
			type: 'post',
	        data: {data:json},
	        cache: false,
	        success: function (successData) {
	        	var message = mini.decode(successData);
	        	var msg = message.msg;//获取组织xxID，用于树节点定位
	        	mini.unmask(document.body);
	        	if(message.type == '200'){
	            	showMsg("xxx添加成功","success",800,"center","center",closeWindow(msg));
	        	}else{
	        		showMsg("xxx添加失败","warning",800,"center","center",closeWindow);
	        	}
	        	
	        },
	        error: function (XMLHttpRequest, textStatus, errorThrown) {
	        	 mini.unmask(document.body);
	        	 showMsg("xx添加错误","danger",800,"center","center",closeWindow);
	        }
	    });
	}
	//更新xx信息
	function personUpdate(json){
		$.ajax({
	        url: basePath+"example/person/update",
			type: 'post',
	        data: { data: json},
	        cache: false,
	        success: function (successData) {
	        	var message = mini.decode(successData);
	        	var msg = message.msg;//获取组织xxID，用于树节点定位
	        	mini.unmask(document.body);
	        	if(message.type == '200'){
        			showMsg("xx更新成功","success",800,"center","center",closeWindow(msg));
	        	}else{
	        		showMsg("xx更新失败","warning",800,"center","center",closeWindow);
	        	}
	        },
	        error: function (jqXHR, textStatus, errorThrown) {
	        	mini.unmask(document.body);
	            showMsg("xx更新错误","danger",800,"center","center",closeWindow);
	        }
	    });
	}
	
	
	function saveData() {
	    var o = form.getData(); 
	    form.validate();
	    if (form.isValid() == false) return;
	    var json = mini.encode(o);
	    mini.mask({
	        el: document.body,
	        cls: 'mini-mask-loading',
	        html: '加载中...'
	    });
	    
	    if (action == "edit"){
	        personUpdate(json);
	    }else{
	    	personAdd(json);
	    }
	}
	
	
	function onOk(){
		saveData();
	}
	
	function closeWindow(action) {
	    if (action == "close" && form.isChanged()) {
	        if (confirm("数据被修改了，是否先保存？")) {
	            return false;
	        }
	    }
	    if (window.CloseOwnerWindow) return window.CloseOwnerWindow(action);
	    else window.close();            
	}
	
	function onCancel(){
		closeWindow("close");
	}
/*]]>*/
</script>
</html>